package com.jiot.plugin.qiniu;

import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.IPlugin;
import com.qiniu.util.Auth;

public class QiniuPlugin implements IPlugin{
	
	private String accessKey;
	private String secretKey;
	private long expireSeconds;
	private Auth auth;
	private String syhost;//私有
	private String gghost;//公共
	
	public QiniuPlugin(String configFile){
		Prop prop = PropKit.use(configFile);
		this.accessKey = prop.get("qiniu.accessKey");
		this.secretKey = prop.get("qiniu.secretKey");
		this.expireSeconds = prop.getLong("qiniu.expireSeconds");
		this.syhost = prop.get("qiniu.syhost");
		this.gghost = prop.get("qiniu.gghost");
	}
	
	public QiniuPlugin(String accessKey,String secretKey,long expireSeconds){
		this.accessKey = accessKey;
		this.secretKey = secretKey;
		this.expireSeconds = expireSeconds;
	}
	
	@Override
	public boolean start() {
		if(this.auth == null) {
			this.auth = Auth.create(this.accessKey, this.secretKey);
			QiniuKit.init(this.auth, this.expireSeconds, this.syhost, this.gghost);
		}
		return true;
	}

	@Override
	public boolean stop() {
		// TODO Auto-generated method stub
		return false;
	}

	public String getAccessKey() {
		return accessKey;
	}

	public void setAccessKey(String accessKey) {
		this.accessKey = accessKey;
	}

	public String getSecretKey() {
		return secretKey;
	}

	public void setSecretKey(String secretKey) {
		this.secretKey = secretKey;
	}

	public Auth getAuth() {
		return auth;
	}

	public void setAuth(Auth auth) {
		this.auth = auth;
	}

	public long getExpireSeconds() {
		return expireSeconds;
	}

	public void setExpireSeconds(long expireSeconds) {
		this.expireSeconds = expireSeconds;
	}
	
	
}
